package com.lean.android.adsdk

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.lean.android.ad.core.AdLoaders
import com.lean.android.ad.core.AdSdk
import com.lean.android.ad.utils.StatusBarHelper
import com.lean.android.adsdk.databinding.ActivityFeedAdBinding
import com.qmuiteam.qmui.arch.QMUIActivity

class FeedAdActivity : QMUIActivity() {

    private lateinit var binding: ActivityFeedAdBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBarHelper.translucent(this)
        StatusBarHelper.setStatusBarLightMode(this)

        binding = ActivityFeedAdBinding.inflate(layoutInflater)
        setContentView(binding.root)

//        AdConfigCache.isBlack = false
//        AdConfigCache.isCompliant = false

        binding.topBar.setTitle("信息流广告")
        binding.topBar.addLeftBackImageButton().onThrottleClick {
            finish()
        }

        binding.adSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
            Toast.makeText(this, "广告开关： $isChecked", Toast.LENGTH_SHORT).show()
            AdSdk.isVip = isChecked

            if (isChecked) {
                AdLoaders.removeCurrentFeedAd(this)
            }
        }

        binding.adSwitch.isChecked = AdSdk.isVip

        binding.topBar.addRightTextButton("刷新", R.id.id_refresh).onThrottleClick {
            AdLoaders.startFeedAd(this, binding.feedAd, onAdShown = { ad, w, h ->
                Log.d("Feed", "startFeedAd: onAdShown , width $w, height $h")
            })
        }

        AdLoaders.startFeedAd(this, binding.feedAd, onAdShown = { ad, w, h ->
            Log.d("Feed", "startFeedAd: onAdShown , width $w, height $h")
        })
    }
}